package com.cx.sync;

import java.util.concurrent.*;

/**
 *
 *
 * synchronized  jvm内置锁  Unsafe
 */
public class SynchronizedTest {

    public  synchronized void test() throws InterruptedException {
//        synchronized (this){
            System.out.println(Thread.currentThread().getName()+"start in ");
//            wait();
            TimeUnit.SECONDS.sleep(5);
            System.out.println(Thread.currentThread().getName()+"end in ");
//        }
    }

    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                try {
                    SynchronizedTest test = new SynchronizedTest();
                    test.test();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
        while (true){
        }
    }
}
